﻿using AzureFileDepot.HelperClasses;
using AzureFileDepot.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace PublishingConsole
{
    class Program
    {
        static ServiceBusTopic topic;

        static void Main(string[] args)
        {
            topic = new ServiceBusTopic(Properties.Settings.Default.ServiceBusTopic, "filepublication");

            FileWatcher watcher = new FileWatcher(Properties.Settings.Default.FileWatchLocation, "*.*");

            watcher.Start(FileFound);

            while (true)
            {
                // do something ???
                Thread.Sleep(500);
            }
        }

        public static void FileFound(FileInfo foundFileInfo, Stream foundFileStream)
        {
            // use blockblob and service bus helpers to upload file and broadcast
            AzureBlob newBlob = new AzureBlob(Properties.Settings.Default.AzureStorageConnection, Properties.Settings.Default.UploadContainer);
            newBlob.uploadFromStream(foundFileStream, foundFileInfo.Name);

            topic.SendMessage(newBlob.CreateReadSaS(Properties.Settings.Default.UploadContainer, foundFileInfo.Name));
        }

    }
}
